/**
 * @name ScrollGenericView
 * @constructs The default constructor.
 * @augments Animation.AANode
 *
 *
 */
exports.ScrollGenericView = Animation.AANode.subclass({
	
	initialize: function(descriptionBlock,currentOutputIndex) 
	{
		this._blocks = [];
		this._friendsDictionary = null;
		var friendsDictionary = null;
		MMFriendManager.getFriendsDictionary(this.getFriendsSuccessCallback.bind(this));
	},
	
	getFriendsSuccessCallback: function(friendsDictionary)
	{
		this._friendsDictionary = friendsDictionary;
		this.createView();
		if(!TutorialManager.getHasCompletedTutorial())
		{
			var bottomBar = MMGameLayer.getControlLayer().getBottomBar();
			bottomBar.showLeftTutorialIndicatorForMenu();
		}
	},
	createView: function()
	{
		if(this._friendsDictionary)
		{
			var allKeys = this._friendsDictionary.allKeys();
			var friendsCount = allKeys.length;
			for(var i = 0; i < friendsCount; i++)
			{
				var friend = this._friendsDictionary.objectForKey(allKeys[i]);
				var block = new SocialScrollViewCell(friend);
				this._blocks.push(block);
			}
			if(friendsCount > 0)
			{	
				var blockSize = new Core.Size(TCUtil.adjustWidthWithDevice(100),TCUtil.adjustHeightWithDevice(100));
				var browserSize = new Core.Size(TCUtil.adjustWidthWithDevice(320),TCUtil.adjustHeightWithDevice(100));
				var browserPosition = new Core.Vector(TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(50));										 
				
				var browserOptions = new Browser.PagedBrowserOptions();
				browserOptions.browserSize = browserSize;
				browserOptions.origin = browserPosition;
				browserOptions.blocksPerPage = 3;
				this._browser = new Browser.PagedBrowser(blockSize, this._blocks, browserOptions,null,0);
				this._browserTT = this._browser.getTouchTarget();
				
				this._browserTT.setDepth(10);
				this._browser.setDepth(10);
		                                                 
				this.addChild(this._browserTT);
				this.addChild(this._browser);
		        
		        var slideToPage = parseInt(0);
		        this._browser.jumpToPage(0);
			}
			else
			{
				var alertBox = UIFactory.getAlertBox("Message", "You have no friends please add some from Mobage.", ["ok"], this);
			}
		}
		else
		{
			var alertBox = UIFactory.getAlertBox(Core.Localization.getString("ERROR"), Core.Localization.getString("SOME_ERROR"), ["ok"], this);
		}
	},
	
	setEnabled: function(enable) {
		this._browserTT.setTouchable(enable);
		this._browser.setVisible(enable);
	},
	
	destroy: function($super) {
		for (var i = 0; i < this._blocks; i++)
		{
			this._blocks[i].destroy();
		}
		for (var i = this._children.length - 1; i >= 0; i--) {
			this._children[i].destroy();
		}
		$super();
	},
});
